package com.sjgtw.cloud.web.organization.service.impl;

import com.sjgtw.cloud.common.core.constant.CacheConstants;
import com.sjgtw.cloud.common.core.utils.DateUtils;
import com.sjgtw.cloud.common.core.utils.SecurityUtils;
import com.sjgtw.cloud.common.redis.service.RedisService;
import com.sjgtw.cloud.system.api.model.LoginUser;
import com.sjgtw.cloud.web.organization.domain.OrganizationDetails;
import com.sjgtw.cloud.web.organization.mapper.OrganizationDetailsMapper;
import com.sjgtw.cloud.web.organization.service.IOrganizationDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 应急组织管理详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-15
 */
@Service
public class OrganizationDetailsServiceImpl implements IOrganizationDetailsService
{
    @Autowired
    private OrganizationDetailsMapper organizationDetailsMapper;

    @Autowired
    private RedisService redisService;

    /**
     * 查询应急组织管理详情
     * 
     * @param id 应急组织管理详情主键
     * @return 应急组织管理详情
     */
    @Override
    public OrganizationDetails selectOrganizationDetailsById(Long id)
    {
        return organizationDetailsMapper.selectOrganizationDetailsById(id);
    }

    /**
     * 查询应急组织管理详情列表
     * 
     * @param organizationDetails 应急组织管理详情
     * @return 应急组织管理详情
     */
    @Override
    public List<OrganizationDetails> selectOrganizationDetailsList(OrganizationDetails organizationDetails)
    {
        return organizationDetailsMapper.selectOrganizationDetailsList(organizationDetails);
    }

    /**
     * 新增应急组织管理详情
     * 
     * @param organizationDetails 应急组织管理详情
     * @return 结果
     */
    @Override
    public int insertOrganizationDetails(OrganizationDetails organizationDetails)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        organizationDetails.setCreateBy(user.getUsername());
        organizationDetails.setCreateTime(DateUtils.getNowDate());
        return organizationDetailsMapper.insertOrganizationDetails(organizationDetails);
    }

    /**
     * 修改应急组织管理详情
     * 
     * @param organizationDetails 应急组织管理详情
     * @return 结果
     */
    @Override
    public int updateOrganizationDetails(OrganizationDetails organizationDetails)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        organizationDetails.setUpdateBy(user.getUsername());
        organizationDetails.setUpdateTime(DateUtils.getNowDate());
        return organizationDetailsMapper.updateOrganizationDetails(organizationDetails);
    }

    /**
     * 批量删除应急组织管理详情
     * 
     * @param ids 需要删除的应急组织管理详情主键
     * @return 结果
     */
    @Override
    public int deleteOrganizationDetailsByIds(Long[] ids)
    {
        return organizationDetailsMapper.deleteOrganizationDetailsByIds(ids);
    }

    /**
     * 删除应急组织管理详情信息
     * 
     * @param id 应急组织管理详情主键
     * @return 结果
     */
    @Override
    public int deleteOrganizationDetailsById(Long id)
    {
        return organizationDetailsMapper.deleteOrganizationDetailsById(id);
    }
}
